"use strict"

var Router = require('koa-router');
var config = require('../../../config/config.js');
var Empty = require('../../../model/empty.js');
var EmptyDao = require('../../../modelDao/empty.js');

// console.log(config.baseUrl + '/v1/_empty');

var router = new Router({
    prefix: config.baseUrl + '/v1/_empty'
});

router.get('/test', function*() {
    // console.log('%s %s', this.method, this.url);
    this.body = 'test work fine';
});

router.post('/', function*() {
    try {
        var inParams = JSON.parse(this.request.body);
    } catch (e) {
        this.body = 'error : input must be json';
        return;
    }

    var aEmpty = new Shop(inParams);
    console.log(aEmpty);

    try {
        var result = yield EmptyDao.save(aEmpty);
        this.body = JSON.stringify(result);
    } catch (e) {
        this.body = 'save error ' + e.toString();
    }
});

module.exports = router;